/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
import queenb.net.entitybean.M010;
import queenb.web.store.M010Store;
import queenb.web.util.ComboboxUtil;
import queenb.web.util.SessionProvider;
import queenb.web.util.Util;

/**
 *
 * @author Nguyen Hung
 */
public class M010Controller extends QueenbController {

    private int pm010;
    private String mv011;// City Name
    private String mv012;// abbreviation
    private int beginContructor;
    
    private int fm000;// id of country
    private M010Store m010Store;
    private List<SelectItem> combolistM010= new ArrayList<SelectItem>();
    private ComboboxUtil comboboxUtil;

    public M010Controller() throws SQLException, InstantiationException, IllegalAccessException {
        m010Store = new M010Store();
       Object action = getRequest().getParameter("action");
       if(action!=null){
           if(action.equals("getcontentsms")){
               Object obMv012 = getRequest().getParameter("mv012");
               if(obMv012!=null){
                   SessionProvider.setSessionMapValue("STRINGMV012", obMv012);
                   System.out.println("----------VALUE--------"+SessionProvider.getSessionMapValue("STRINGMV012"));
               }
           }else if (action.equals("editM010")) {
                Object objPM010 = getRequest().getParameter("pm010");
                if (objPM010 != null) {
                    pm010 = Util.parseInt(objPM010);

                    List<M010> list = m010Store.mcurpks_listoftabm000(getLogin().getModule(), getLogin().getCompanyNo(), 0, getLogin().getUserName());
                    if (list != null) {
                        for (int i = 0; i < list.size(); i++) {
                            if (list.get(i).getPm010() == pm010) {
                                mv011 = list.get(i).getMv011();
                                mv012 = list.get(i).getMv012(); 
                                fm000 = list.get(i).getFm000();
                            }
                        }
                    }
                }
            } else if (action.equals("deleteM010")) {
                Object objPM000 = getRequest().getParameter("pm010");
                if (objPM000 != null) {
                    pm010 = Util.parseInt(objPM000);
                    SessionProvider.setSessionMapValue("IDM010DELETE", pm010);
                }
            }
       }
    }

    public void stdm_tools_inserttabm010() {
        System.out.println("--------------" + mv011+mv012);
        if(SessionProvider.getSessionMapValue("STRINGMV012")!=null){
            mv012 = SessionProvider.getSessionMapValue("STRINGMV012").toString();
        }
        System.out.println("-----INSERT-----VALUE--------"+mv012);
            int count = m010Store.stdm_tools_inserttabm000(pm010,mv011,mv012,fm000,getLogin().getUserName());
            if (count > 0) {
                showGlobalReport(true, getResourceString("success"));
            } else {
                showGlobalReport(true, getResourceString("error"));
            }          
        sendRedirectUrlTab("setting.jsp?tab=header37&linkM000="+Util.convertMD5(getRequest().getRequestURI()));

    }
    public void onchangeTemplate() {
     try {
         System.out.println("----------TEMPLATE--" + fm000);
         if(fm000 ==3){
             setFm000(3);
             setMv012("Nhan dip {P1} Sai Gon Travel kinh chuc Quy khach {P2}");
         }else if(fm000 ==4){
              setFm000(4);
             setMv012("Xin tran trong thong bao Quy khach di tour {P1} ngay {P2}, vui long co mat luc {P3} tai {P4}. HDV: {P5}. Kinh chuc Quy khach co mot chuyen di vui ve.");
         }else if(fm000 ==5){
              setFm000(5);
             setMv012("Khach theo doan {P1} di {P2} luu y: co mat dung gio de tham gia phong van voi DSQ/LSQ {P3} luc {P4} tai {P5}. Khi di vui long mang theo {P6}. HDV: {P7}");
         }else if(fm000 ==6){
              setFm000(6);
             setMv012("Happy birthday to you! SaiGon Travel kinh chuc {P1} co mot ngay sinh nhat vui ve,hanh phuc ben nguoi than va ban be.Kinh tang Quy Khach {P2}. LH: {P3}");
         }
         System.out.println("-------AAAAAA---TEMPLATE--" + mv012);
     } catch (Exception e) {
     }
 }
    public List<M010> getListAllCity(){
        try {
            List<M010> listM010 = m010Store.mcurpks_listoftabm000(getLogin().getModule(),getLogin().getCompanyNo(),fm000,getLogin().getUserName());
            return listM010;
        } catch (Exception e) {
            return null;
        }
    }
//    public void getListDetalCity(int id){
//        try {
//            List<A000> listByID = getListAllCity();
//            if(listByID != null && listByID.size() > 0){
//                for(int i=0; i < listByID.size();i++){
//                    if(listByID.get(i).getPa000() == id){
//                        this.av001 = listByID.get(i).getAv001();
//                        this.av002 = listByID.get(i).getAv002();
//                        this.fn750 = listByID.get(i).getFn750();
//                        break;
//                    }
//                }
//            }
//        } catch (Exception e) {
//        }
//    }

    /**
     * @return the pm010
     */
    public int getPm010() {
        return pm010;
    }

    /**
     * @param pm010 the pm010 to set
     */
    public void setPm010(int pm010) {
        this.pm010 = pm010;
    }

    /**
     * @return the mv011
     */
    public String getMv011() {
        return mv011;
    }

    /**
     * @param mv011 the mv011 to set
     */
    public void setMv011(String mv011) {
        this.mv011 = mv011;
    }

    /**
     * @return the mv012
     */
    public String getMv012() {
        return mv012;
    }

    /**
     * @param mv012 the mv012 to set
     */
    public void setMv012(String mv012) {
        this.mv012 = mv012;
    }

    /**
     * @return the fm000
     */
    public int getFm000() {
        return fm000;
    }

    /**
     * @param fm000 the fm000 to set
     */
    public void setFm000(int fm000) {
        this.fm000 = fm000;
    }

    /**
     * @return the combolistM010
     */
    public List<SelectItem> getCombolistM010() {
         try {
             comboboxUtil = new ComboboxUtil();
            combolistM010 = comboboxUtil.getSelectedM000Comb();
        } catch (Exception e) {
            combolistM010 = new ArrayList<SelectItem>();
        }
        return combolistM010;
    }

    /**
     * @param combolistM010 the combolistM010 to set
     */
    public void setCombolistM010(List<SelectItem> combolistM010) {
        this.combolistM010 = combolistM010;
    }

    /**
     * @return the beginContructor
     */
    public int getBeginContructor() {
        return beginContructor;
    }

    /**
     * @param beginContructor the beginContructor to set
     */
    public void setBeginContructor(int beginContructor) {
        this.beginContructor = beginContructor;
    }
   
}
